# Copyright 2024 Henrique Paone
#
# This file is part of Kitty-Visual.
#
# Kitty-Visual is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
# 
# Kitty-Visual is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# Kitty-Visual. If not, see <https://www.gnu.org/licenses/>.

module Tui
  Ansi_regex = /\x1b\[[0-9;:]*[mGKHF]/ 
  
  def move_cursor(line, col)
    printf "\e[%d;%dH", line, col
  end

  def move_cursor_left
    print "\e[D"
  end

  def save_cursor
    print "\e7" 
  end

  def restore_cursor
    print "\e8"
  end
  
  def redraw
    printf "\e[?1049h"
    printf "\e[?1049l"
  end

  def clear_current_line
    print "\e[0K"
  end

  def erase_char
    printf "\e[1X"
  end

  def backspace
    move_cursor_left
    erase_char
  end

  def scroll_down(lines)
    print "\e[#{ lines }S"
  end
  
  def scroll_up(lines)
    print "\e[#{ lines }T"
  end
end
